﻿@{
    ViewBag.Title = "房产资料管理";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    var keyValue = request('keyValue');
    var _organizeid = request('OrganizeId');
    var _pstructId = request('PstructId'); _type = 5;
    var _State = "", _HouseTypeName = "";
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        if (!_organizeid) {
            _organizeid = '@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId';
        }
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth($('.gridPanel').width());
                $("#gridTable").setGridHeight($(window).height() - 141.5);
                $("#itemTree").setTreeHeight($(window).height() - 51.5);
            }, 200);
            e.stopPropagation();

        });
        //var wc = document.getElementsByClassName("ui-layout-center")[0];
        //var we = document.getElementsByClassName("ui-layout-east")[0];
        //var we2 = document.getElementsByClassName("ui-layout-resizer")[1];
        //var width = wc.style.width.split('px')[0] * 0.9;
        //var width2 = parseFloat(wc.style.width.split('px')[0] * 0.1) + parseFloat(we.style.width.split('px')[0]);
        //var width3 = parseFloat(we2.style.right.split('px')[0]) + parseFloat(wc.style.width.split('px')[0] * 0.15);
        //wc.style.width = width + "px";
        //we.style.width = width2 + "px";
        //we2.style.right = width2 + "px";

        //组织机构
        $("#PStructTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            description: "==请选择组织机构==",
            height: "250px",
            click: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    GetTree();
                    _pstructId = "";
                    $('#btn_Search').trigger("click");
                }
            }
        });

        $("#PStructTree").ComboBoxTreeSetValue(_organizeid);

        //房产性质
        $("#Type").ComboBox({
            // data: [{ "key": 1, "value": "楼盘" }, { "key": 2, "value": "楼阁|楼栋|单元|梯" }, { "key": 3, "value": "车库|广告位区域|场地区域|冷库" }, { "key": 4, "value": "楼层|网点" }, { "key": 5, "value": "房间|床位" }],
            url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson",
            param: { EnCode: "PstructType" },
            id: "value",
            text: "text",
            height: "200px"
        }).bind("change", function () {
            _type = parseInt($("#Type").attr("data-value"));
            if (_type == 5) {
                //户型
                $("#HouseTypeName").show();
                $("#State").show();
                $("#HouseTypeName").ComboBox({
                    url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson",
                    param: { EnCode: "HouseType" },
                    id: "value",
                    text: "text",
                    description: "==房间户型==",
                    click: function (item) {
                        _HouseTypeName = $("#HouseTypeName").attr("data-value");
                        $('#btn_Search').trigger("click");
                    }
                });
                $("#State").ComboBox({
                    data: [{ "key": 0, "value": "准备房" }, { "key": 1, "value": "待租" }, { "key": 2, "value": "已选取" }, { "key": 3, "value": "已租" }, { "key": 6, "value": "续租中" }, { "key": 7, "value": "维修中" }],
                    id: "key",
                    text: "value",
                    height: "200px",
                    description: "==房间状态==",
                    click: function (item) {
                        _State = $("#State").attr("data-value");
                        $('#btn_Search').trigger("click");
                    }
                });
                $("#lr-editState").show();
            } else {
                $("#HouseTypeName").hide();
                $("#State").hide();
                $("#lr-editState").hide();
            }
            $("#btn_Search").trigger("click");
        });
        $("#Type").ComboBoxSetValue(_type);
    }

    function GetTree() {
        var item = {
            height: $(window).height() - 51.5,
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?type=5&IsSubstep=true&organizeid=" + _organizeid,
            onnodeclick: function (item) {
                if (_pstructId != item.id) {
                    _pstructId = item.id;
                    $('#btn_Search').trigger("click");
                }
            }
        };
        //初始化
        $("#itemTree").treeview(item);
        if (!!_pstructId) {
            var re = new RegExp("-", "g");
            $("#itemTree_" + _pstructId.replace(re, '_')).addClass("bbit-tree-selected");
        }
    }
    //加载表格
    function GetGrid() {
        var HouseType, HouseTypeName;
        $.SetForm({
            url: "../../SystemManage/DataItemDetail/GetDataItemListJson",
            param: { EnCode: "HouseDirect" },
            success: function (data) {
                HouseType = data;
            }
        });

        $.SetForm({
            url: "../../SystemManage/DataItemDetail/GetDataItemListJson",
            param: { EnCode: "HouseType" },
            success: function (data) {
                HouseTypeName = data;
            }
        });
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["PStructId"] = _pstructId;
        queryJson["OrganizeId"] = _organizeid;
        queryJson["Type"] = _type;
        queryJson["State"] = _State;
        queryJson["HouseTypeName"] = _HouseTypeName;
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_PStructs/GetPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'id', hidden: true },
                { label: '公司Id', name: 'organizeid', hidden: true },
                { label: 'sort', name: 'sort', hidden: true },
                 //{
                 //    label: "", name: "", width: 50, align: "left", sortable: false
                 //    , formatter: function (cellvalue, options, rowObject) {
                 //        return "<a onclick='btn_Details(\"" + rowObject.id + "\")' style='cursor: pointer;color:#EAC100'><i class='fa fa-folder'></i></a>";
                 //    }
                 //},
                {
                    label: "房产名称", name: "allname", width: 200, align: "left", sortable: true
                     , formatter: function (cellvalue, options, rowObject) {
                         switch (rowObject.type) {
                             case 1: return "<i class='fa fa-university'></i>" + cellvalue; break;
                             case 2: return "<i class='fa fa-building-o'></i>" + cellvalue; break;
                             case 3: return "<i class='fa fa-server'></i>" + cellvalue; break;
                             case 5: {
                                 if (rowObject.activemark == 1) {
                                     return "<i class='fa fa-cube' style='color:#2df12d'></i>" + cellvalue;
                                 }
                                 else {
                                     return "<i class='fa fa-cube'></i>" + cellvalue;
                                 }
                             }; break;

                             default:
                                 return "<i class='fa fa-th-list'></i>" + cellvalue;
                                 break;
                         }
                     }
                },
                 {
                     label: "房产编号", name: "code", width: 100, align: "left", sortable: true
                 },
                {
                    label: "户型", name: "housetypename", width: 100, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        var Name = "";
                        $(HouseTypeName).each(function (index, data) {
                            if (data.ItemValue == cellvalue) {
                                Name = data.ItemName;
                                return;
                            }
                        });
                        return Name;
                    }
                },
                {
                    label: "朝向", name: "housetype", width: 100, align: "left", sortable: true,
                    //formatter: function (cellvalue, options, rowObject) {
                    //    var Name = "";
                    //    $(HouseType).each(function (index, data) {
                    //        if (data.ItemValue == cellvalue) {
                    //            Name = data.ItemName;
                    //            return;
                    //        }
                    //    });
                    //    return Name;
                    //}
                },
                { label: "建筑面积", name: "area", width: 100, align: "left", sortable: true },
                { label: "规划业态", name: "planningformat", width: 100, align: "left", sortable: true, hidden: true },
                {
                    label: "状态", name: "state", width: 100, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "准备房";
                            case 1: return "待租";
                            case 2: return "已选取";
                            case 3: return "已租";
                            case 4: return "自用";
                            case 5: return "已售";
                            case 6: return "续租中";
                            case 7: return "维修中";
                            default: return "";
                        }
                    }
                },

                { label: "月租金", name: "monthlyrent", width: 100, align: "left", sortable: true },
                {
                    label: "起租日期", name: "emoveindate", width: 100, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }
                },
                //{
                //    label: "标识方式", name: "flagway", width: 80, align: "left", sortable: true, hidden: true,
                //    formatter: function (cellvalue, options, rowObject) {
                //        switch (cellvalue) {
                //            case 0: return "无标识";
                //            case 1: return "rfid芯片";
                //            case 2: return "条码";
                //            case 3: return "二维码";
                //            case 4: return "beacon";
                //            default: return "";
                //        }
                //    }
                //},
                //{ label: "标识编码", name: "flagno", width: 200, align: "left", sortable: true, hidden: true },
                //{ label: "租户名称", name: "CustomerInfoName", width: 100, align: "left", sortable: true, hidden: true },
                //{ label: "经营品牌", name: "Brand", width: 100, align: "left", sortable: false, hidden: true },
                //{ label: "联系人", name: "LinkMan", width: 100, align: "left", sortable: false, hidden: true },
                //{ label: "联系人电话", name: "LinkPhone", width: 100, align: "left", sortable: false, hidden: true },
                //{ label: "合同开始时间", name: "BDate", width: 100, align: "left", sortable: false, hidden: true },
                //{ label: "合同终止时间", name: "EDate", width: 100, align: "left", sortable: false, hidden: true },
                {
                    label: "发布状态", name: "ispublish", index: "ispublish", width: 70, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        switch (cellvalue) {
                            case 0: return "未发布";
                            case 1: return "发布中";
                            case 2: return "已发布";
                            case 3: return "发布失败";
                            default: return "";
                        }
                    }
                },
                { label: "招租标题", name: "renttitle", width: 100, align: "left", sortable: true },
                    {
                        label: "是否审核", name: "auditmark", index: "auditmark", width: 150, align: "left", sortable: true, hidden: true,
                        formatter: function (cellvalue, options, rowObject) {
                            if (cellvalue == "1") {
                                return "<i class='fa fa-check fa-2x' style='color:green;margin-left:10px;' ><i/>";
                            }
                            else {
                                return "";
                            }
                        }
                    },
                { label: "附加说明", name: "memo", width: 100, align: "left", sortable: false },
                { label: "", name: "juniornum", width: 100, align: "left", sortable: true },
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortable: true,
            sortname: 'code',
            sortorder: 'asc',
            rownumbers: false,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (rowid) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                if ($("#gridTable").jqGridRowValue("state") == "维修中") {
                    $("#lr-editState").removeAttr("disabled");
                }
                else {
                    $("#lr-editState").attr("disabled", "disabled");
                }
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });

        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            queryJson["PStructId"] = _pstructId;
            queryJson["OrganizeId"] = _organizeid;
            queryJson["keyword"] = $("#txt_Keyword").val();
            queryJson["Type"] = _type;
            queryJson["State"] = _State;
            queryJson["HouseTypeName"] = _HouseTypeName;
            $gridTable.jqGrid('setGridParam', {
                postData: {
                    queryJson: JSON.stringify(queryJson)
                },
                page: 1
            }).trigger('reloadGrid');
        });
        //查询回车事件
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });


    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加房产',
            url: '/ResourceManage/RS_PStructs/Form?organizeId=' + _organizeid,
            width: "1000px",
            height: "850px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };

    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (checkedRow(keyValue)) {
            var organizeId = $("#gridTable").jqGridRowValue("organizeid");
            dialogOpen({
                id: "Form",
                title: '修改房产',
                url: '/ResourceManage/RS_PStructs/Form?organizeId=' + organizeId + "&keyValue=" + keyValue,
                width: "1000px",
                height: "850px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })
        }
    }

    //修改房间状态
    function btn_editState() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '修改房间状态',
                url: '/ResourceManage/RS_PStructs/UpdateState?keyValue=' + keyValue,
                width: "450px",
                height: "350px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })
        }
    }

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../ResourceManage/RS_PStructs/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的数据项！', 0);
        }
    }

    function btn_export() {
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["PStructId"] = _pstructId;
        queryJson["OrganizeId"] = _organizeid;
        queryJson["keyword"] = $("#txt_Keyword").val();
        queryJson["Type"] = _type;
        queryJson["State"] = _State;
        queryJson["HouseTypeName"] = _HouseTypeName;
        debugger;
        location.href = "../../ResourceManage/RS_PStructs/GetExportList?queryJson=" + JSON.stringify(queryJson);
    }


    function btn_Details(keyValue) {
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '查看详情',
                btn: null,
                url: '/ResourceManage/RS_PStructs/Detail?keyValue=' + keyValue,
                width: "1000px",
                height: "650px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })
        }
    }


    function btn_disabled() {
        $.SaveForm({
            url: "../../ResourceManage/RS_PStructs/ExcelImport",
            loading: "正在保存数据...",
            success: function () {
                // $.currentIframe().$("#gridTable").resetSelection();
            }
        })
    }

</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height: 98%;">
            <div class=" panel-title" style="padding:0px;"><div id="PStructTree" type="selectTree" class="ui-select"></div></div>
            <div id="itemTree" style=" height: 98%;"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="queryCondition" class="btn-group">
                                    <div id="Type" type="select" class="ui-select" style="width: 100px;"></div>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" maxlength="20" class="form-control" placeholder="请输入要查询的名称或者编号" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 2px;">
                                <div id="HouseTypeName" type="select" class="ui-select" style="width: 100px;"></div>
                            </td>
                            <td style="padding-left: 2px;">
                                <div id="State" type="select" class="ui-select" style="width: 100px;"></div>
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-editState" class="btn btn-default" onclick="btn_editState()" disabled="disabled"><i class="fa fa-pencil-square-o"></i>&nbsp;修改状态</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                        <a id="lr-export" class="btn btn-default" onclick="btn_export()"><i class="fa fa-sign-out"></i>&nbsp;导出</a>
                    </div>
                    @*<script>$('.toolbar').authorizeButton()</script>*@
                </div>

            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
    @*<div class="ui-layout-east">
            <div class="east-Panel">
                <div class="panel-Title">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#panel1" data-toggle="tab">资料卡片</a>
                        </li>
                        <li>
                            <a href="#panel3" data-toggle="tab">相关操作</a>
                        </li>
                    </ul>
                </div>
                <div class="tab-content">
                    <div class="tab-pane active" id="panel1">
                        <ul class="folder-list" style="border-bottom: 1px dashed #cecece; border-top: 1px dashed #cecece; ">
                            <li>
                                编号：<input type="text" id="Code" readonly="readonly" class="form-control" />
                            </li>
                            <li>
                                名称：<input type="text" id="Name" readonly="readonly" class="form-control" />
                            </li>
                            <li>
                                性质：
                                <select id="Type" disabled class="form-control">
                                    <option value="1">楼盘</option>
                                    <option value="2">楼阁/楼栋/单元/梯</option>
                                    <option value="3">车库/广告位/场地区域/冷库</option>
                                    <option value="4">楼层/网点</option>
                                    <option value="5">房间/床位</option>
                                </select>
                            </li>
                            <li>
                                状态：<input type="text" readonly="readonly" id="State" class="form-control" />
                            </li>
                            <li>
                                业态：<input type="text" readonly="readonly" id="PlanningFormat" class="form-control" />
                            </li>
                            <li>
                                面积：<input type="text" readonly="readonly" id="Area" class="form-control" />
                            </li>
                        </ul>
                        <h5 style=" padding: 10px; background: #edf1f2; ">备注说明</h5>
                        <textarea style="width:100%;height:60px;" readonly="readonly" id="Memo" class="form-control"></textarea>
                        <div class="hr-line-dashed" style="border-top: 1px dashed #e7eaec;    color: #ffffff;    background-color: #ffffff;    height: 1px;    margin: 10px 0;"></div>
                        <h5 style=" padding: 10px; background: #edf1f2; ">图档</h5>
                        <div style="border: 1px solid #cecece; height: 200px;">
                            <img />
                        </div>
                        <div class="hr-line-dashed" style="border-top: 1px dashed #e7eaec;    color: #ffffff;    background-color: #ffffff;    height: 1px;    margin: 10px 0;"></div>


                    </div>
                    <div class="tab-pane" id="panel3">
                        <p>
                            Howdy, I'm in Section 3.
                        </p>
                    </div>
                </div>
            </div>
        </div>*@
    <style>
        .folder-list li {
            padding: 10px 0 10px 5px;
            height: 60px;
        }

        .nav-tabs {
            padding-top: 1px;
        }
    </style>
</div>